<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let str = 'WelcomeToQianfen'
        let arr =[]
        // 元素出现的次数数组
        let strnums = []
        for(var item of str){
            let nums = 0
            // console.log(item);
            arr.push(item)
            for(let ited of str){
                if (ited==item) {
                    nums++
                }    
            }
            strnums.push(nums) 
        }
        console.log(arr);
        console.log(strnums);
        // 2.获取数组中最大值的下标
        let maxindex = 0
        // 数组中最大的值
        let maxitem = strnums[0]
        strnums.forEach((item,j)=>{
            if (item>maxitem) {
                maxindex = j
                maxitem = item  
            }
        })
        console.log(maxindex);
        console.log('出现最多的字母是',str[maxindex])
        
        
        

    </script>
</body>
</html>